//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.CardTypeCodeDao;
import com.aidong.dao.wills.MemberEarnestDao;
import com.aidong.model.wills.MemberEarnest;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"memberEarnestQuery"})
public class MemberEarnestQueryController extends BaseController {
    @Resource
    MemberEarnestDao memberEarnestDao;
    @Resource
    CardTypeCodeDao cardTypeCodeDao;

    public MemberEarnestQueryController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("member/earnestquery/list")).addObject("shopName", this.getTypeList("shopName")).addObject("earnestType", this.getTypeList("earnestType")).addObject("earnestStatus", this.getTypeList("earnestStatus"));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "earnestType",required = false) String earnestType, @RequestParam(value = "dateType",required = false) String dateType, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "saleId",required = false) String saleId, @RequestParam(value = "cardCode",required = false) String cardCode, @RequestParam(value = "custName",required = false) String custName, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "shopCode", shopCode);
        cd.eq("earnestType", earnestType);
        cd.eq("saleId", this.parseInt(saleId));
        if("2".equals(dateType)) {
            if(!this.chkNull(dateFrom)) {
                cd.ge("useDate", this.getDateFrom(dateFrom));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("useDate", this.getDateTo(dateTo));
            }
        } else {
            if(!this.chkNull(dateFrom)) {
                cd.ge("saleDate", this.getDateFrom(dateFrom));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("saleDate", this.getDateTo(dateTo));
            }
        }

        cd.eq("cardCode", cardCode);
        if(!this.chkNull(custName)) {
            cd.like("custName", "%" + custName + "%");
        }

        cd.eq("status", status);
        this.memberEarnestDao.queryPageList(pg, cd, (new OrderSet()).desc("saleDate"));
        ModelAndView mv = new ModelAndView("member/earnestquery/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "earnestType",required = false) String earnestType, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "cardCode",required = false) String cardCode, @RequestParam(value = "custName",required = false) String custName, @RequestParam(value = "status",required = false) Integer status, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, '\uea60');
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "shopCode", shopCode);
            cd.eq("earnestType", earnestType);
            if(!this.chkNull(dateFrom)) {
                cd.ge("saleDate", this.getDateFrom(dateFrom));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("saleDate", this.getDateTo(dateTo));
            }

            cd.eq("cardCode", cardCode);
            if(!this.chkNull(custName)) {
                cd.like("custName", "%" + custName + "%");
            }

            cd.eq("status", status);
            this.memberEarnestDao.queryPageList(e, cd, (new OrderSet()).desc("saleDate"));
            ExportXls xls = new ExportXls(response, "定金销售流水详单", "定金销售流水详单");
            xls.addHead(new String[]{"门店编号", "门店名称", "定金编号", "销售日期", "会员姓名", "证件号码", "手机号码", "会员号", "卡号", "定金金额", "收款金额", "全额定金", "状态", "定金类型", "使用日期", "(退/合并)日期", "销售员", "销售员2", "操作员", "备注", "卡种编号", "卡种名称", "卡价"});
            xls.setWidth(new int[]{10, 10, 10, 20, 10, 20, 15, 20, 10, 10, 10, 10, 10, 10, 20, 20, 15, 15, 15, 20, 10, 20, 10});
            new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                MemberEarnest earnest = (MemberEarnest)i$.next();
                xls.addRow(new Object[]{earnest.getShopCode(), this.cache.getValue("shopName", earnest.getShopCode()), earnest.getSaleId(), sdf2.format(earnest.getSaleDate()), earnest.getCustName(), earnest.getIdNumber(), earnest.getMobile(), earnest.getMemberCode(), earnest.getCardCode(), earnest.getEarnestAmount(), earnest.getPayAmount(), this.chkNullZ(earnest.getAmountFull())?"否":"是", this.cache.getValue("earnestStatus", String.valueOf(earnest.getStatus())), this.cache.getValue("earnestType", earnest.getEarnestType()), earnest.getUseDate() != null?sdf2.format(earnest.getUseDate()):"", earnest.getCancelDate() != null?sdf2.format(earnest.getCancelDate()):"", this.nvl(earnest.getSalesCode()) + " - " + this.nvl(this.cache.getValue("salesName", earnest.getSalesCode())), this.nvl(earnest.getSalesCode2()) + " - " + this.nvl(this.cache.getValue("salesName", earnest.getSalesCode2())), this.nvl(earnest.getCreateUser()) + " - " + this.nvl(this.cache.getValue("userName", earnest.getCreateUser())), earnest.getNote(), earnest.getCardType(), this.cache.getValue("cardType", earnest.getCardType()), earnest.getCardPrice()});
            }

            xls.close();
            this.addUserLog("导出会籍销售流水详单", e.getResultList().size() + "条记录");
        } catch (Exception var16) {
            this.log.error("import", var16);
        }

        return null;
    }
}
